import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_ncsjqz_getx/page/farm/farm_view.dart';
import 'package:flutter_ncsjqz_getx/widget/ink_widget.dart';
import 'package:flutter_ncsjqz_getx/widget/null_widget.dart';
import 'package:flutter_ncsjqz_getx/widget/tab_widget.dart';
import 'package:get/get.dart';

import 'all_farm2_view.dart';
import 'all_farm_logic.dart';

/// <summary>
/// todo: 所有农场
/// author：zwb
/// dateTime： 2021/11/25 15:43
/// filePath： lib/page/all_farm/all_farm_view.dart
/// desc:
/// <summary>
///
class AllFarmPage extends StatefulWidget {
  @override
  _AllFarmPageState createState() => _AllFarmPageState();
}

class _AllFarmPageState extends State<AllFarmPage> {
  final logic = Get.put(AllFarmLogic());

  List video = [
    "http://cctvalih5ca.v.myalicdn.com/live/cctv1_2/index.m3u8",
    "http://220.161.87.62:8800/hls/1/index.m3u8",
    "http://116.199.5.52:8114/00000000/index.m3u8?&Fsv_ctype=LIVES&Fsv_otype=1&FvSeid=5abd1660af1babb4&Fsv_filetype=1&Fsv_ctype=LIVES&Fsv_cid=0&Fsv_chan_hls_se_idx=188&Fsv_rate_id=0&Fsv_SV_PARAM1=0&Fsv_ShiftEnable=0&Fsv_ShiftTsp=0&Provider_id=&Pcontent_id=&Fsv&_res_tag_=video",

  ];
  @override
  void initState() {
    // TODO: implement initState
    super.initState();
    logic.getData();
  }

  @override
  Widget build(BuildContext context) {
    return GetBuilder<AllFarmLogic>(
      builder: (controller) {
        return Scaffold(
          backgroundColor: Colors.white,
          // appBar: appBarWidget(leading: SizedBox(),title: "生态园互联"),
          body: Column(
            children: [
              SafeArea(child: _tabBar(),),

              _body(),
            ],
          ),
        );
      },
    );
  }

  /// todo：分类选择栏
  _tabBar() {
    return tab(
        tabs: ["土地租赁","我的农场监控","所有生态园监控"],
        currentIndex: logic.currentIndex,
        mainAxisAlignment: MainAxisAlignment.start,
        onTap: (val){
          logic.setCurrentIndex(val);
        }
    );
  }

  @override
  void dispose() {
    Get.delete<AllFarmLogic>();
    super.dispose();
  }

  _body(){
    if(logic.currentIndex == 0){
      return Expanded(
        child: FarmPage(),
      );
    }
    if(logic.currentIndex == 1){
      return nullTextWidget("");
    }
    if(logic.currentIndex == 2){
      return _contentBody();
    }
  }

  _contentBody() {
    return logic.xList!.length == 0 ? Center(
      child: InkWidget.text("暂无数据"),
    ): ListView(
      shrinkWrap: true,
      padding: EdgeInsets.all(0),
      children: List.generate(logic.xList!.length, (index){
        return _itemCardItem(index);
      }),
    );
  }

  _itemCardItem(int index) {
    return InkWell(
      onTap: (){
        Get.to(()=>all_farm2Page(id: logic.xList![index].classifyId!,name: logic.xList![index].classifyName!,));
      },
      child: Container(
        width: Get.width,
        color: Colors.grey.shade100,
        margin: EdgeInsets.only(bottom: 15),
        padding: EdgeInsets.all(15),
        child: Column(
          crossAxisAlignment: CrossAxisAlignment.start,
          children: [
            InkWidget.title("${logic.xList![index].classifyName}\n"),
            InkWidget.imgNet("${logic.xList![index].classifyPic}",height: Get.width * 0.5,width: Get.width,fit: BoxFit.cover,),
            InkWidget.text("\n${logic.xList![index].createTime}"),
            Divider(),
          ],
        ),
      ),
    );
  }
}